class LastJiFenCellAwardView extends egret.DisplayObjectContainer{
    private _bg:egret.Bitmap; // 背景
    public awards:any[] = []; // 奖品数组

    constructor(){
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.viewDidLoad, this);
    }

    private viewDidLoad(){
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.viewDidDisappear, this);
    }

    private viewDidDisappear(){
        this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.viewDidDisappear, this);
        // 1.清空视图
        this.removeChildren();
    }

    /*********************************************** public **********************************************************/
    public reloadData(){
        this.removeChildren();
        // 1.背景
        if(!this.contains(this.bg)) this.addChild(this.bg);
        this.updateSubViews();
    }

    /*********************************************** private **********************************************************/
    private updateSubViews(){
        var length = this.awards.length;
        var obj = undefined;
        var lineH = 1;
        var awardView = undefined;
        var shape = undefined;
        var totalH = 5;
        for(var i = 0; i < length; i++){
            obj = this.awards[i];
            // var awardView = new LastJiFenSingleAwardView();
            awardView = LastJiFenSingleAwardView.getObj();
            awardView.x = 10;
            awardView.width = this.width - 2 * awardView.x;
            awardView.y = totalH;
            awardView.iconUrl = obj.prop_img;
            awardView.name = obj.prop_name;
            awardView.describtion = obj.prop_desc;
            awardView.num = obj.count;
            this.addChild(awardView);
            totalH += awardView.height;
            if(i == length - 1){
                this.height = utils.getMaxY(awardView);
                this.bg.height = this.height;
                return;   
            }
            shape = new egret.Shape();
            shape.x = awardView.x;
            shape.y = awardView.y + awardView.height;
            shape.graphics.lineStyle(lineH, 0xffffff, 0.3, null, null, null, null, null, [20,10]);
            shape.graphics.moveTo(0, 0);
            shape.graphics.lineTo(awardView.width, 0);
            shape.graphics.endFill();
            totalH += lineH;
            this.addChild(shape);
        }
    }

    /*********************************************** getter **********************************************************/
    
    private get bg():egret.Bitmap{
        if(!this._bg){
            var bg = utils.createBitmapByName('bg_bh', {width:this.width});
            bg.scale9Grid = new egret.Rectangle(44, 28, 293, 114);
            this._bg = bg;
        }
        return this._bg;
    }
}